<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>ListView上拉加载下拉刷新 | 不忘初心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="目前下拉刷新已经满大街都是，在自己的应用如果不使用这个模式的话，出门都不好意思和人家打招呼.">
<meta property="og:type" content="article">
<meta property="og:title" content="ListView上拉加载下拉刷新">
<meta property="og:url" content="http://example.com/2017/07/06/ListView/ListView--ListView%E4%B8%8A%E6%8B%89%E5%8A%A0%E8%BD%BD%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0/index.html">
<meta property="og:site_name" content="不忘初心">
<meta property="og:description" content="目前下拉刷新已经满大街都是，在自己的应用如果不使用这个模式的话，出门都不好意思和人家打招呼.">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170707112738.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170707113145.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708181820.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708182459.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708185730.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708184403.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708191158.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708191631.png">
<meta property="og:image" content="http://images.wxyass.com/wxyass/images/20170708191904.png">
<meta property="article:published_time" content="2017-07-06T09:04:50.000Z">
<meta property="article:modified_time" content="2017-09-29T08:02:31.000Z">
<meta property="article:author" content="wxyass">
<meta property="article:tag" content="ListView">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://images.wxyass.com/wxyass/images/20170707112738.png">
  
    <link rel="alternate" href="/atom.xml" title="不忘初心" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">不忘初心</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-ListView/ListView--ListView上拉加载下拉刷新" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2017/07/06/ListView/ListView--ListView%E4%B8%8A%E6%8B%89%E5%8A%A0%E8%BD%BD%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0/" class="article-date">
  <time class="dt-published" datetime="2017-07-06T09:04:50.000Z" itemprop="datePublished">2017-07-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/ListView/">ListView</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      ListView上拉加载下拉刷新
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>目前下拉刷新已经满大街都是，在自己的应用如果不使用这个模式的话，出门都不好意思和人家打招呼.  </p>
<span id="more"></span>  


<p>参考:  </p>
<p><a target="_blank" rel="noopener" href="https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh">官方Github地址</a><br><a target="_blank" rel="noopener" href="https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh/blob/master/README-cn.md">官方中文版文档</a><br><a target="_blank" rel="noopener" href="https://android-ultra-ptr.liaohuqiu.net/cn/">原作者的分析</a>  </p>
<p>轮子的制造原理就不说了,网上很多,或许以后会懂,现在的关键是如何使用轮子  </p>
<h4 id="一-下载aar文件-并导入工程"><a href="#一-下载aar文件-并导入工程" class="headerlink" title="一 下载aar文件,并导入工程"></a>一 下载aar文件,并导入工程</h4><p>1 下载aar文件   </p>
<ol>
<li><a target="_blank" rel="noopener" href="https://oss.sonatype.org/content/repositories/releases/in/srain/cube/ultra-ptr/1.0.11/">原作者官方下载</a> ultra-ptr-1.0.11.aar      </li>
<li><a target="_blank" rel="noopener" href="http://oss.wxyass.com/wxyass/jar/ultra-ptr-1.0.11.aar">个人备份下载</a>   ultra-ptr-1.0.11.aar  </li>
</ol>
<p>2 导入工程libs文件夹,并修改build.gradle代码.     </p>
<pre><code>repositories &#123;
    flatDir &#123;
        dirs &#39;libs&#39;
    &#125;
&#125;
-------------------------------------------
compile(name:&#39;ultra-ptr-1.0.11&#39;,ext:&#39;aar&#39;)   
</code></pre>
<p>如图:<br><img src="http://images.wxyass.com/wxyass/images/20170707112738.png">     </p>
<p>3 Sync Gradle 一下<br><img src="http://images.wxyass.com/wxyass/images/20170707113145.png">  </p>
<h4 id="二-之前写过一个简单listview的使用-在此基础做下拉刷新"><a href="#二-之前写过一个简单listview的使用-在此基础做下拉刷新" class="headerlink" title="二 之前写过一个简单listview的使用,在此基础做下拉刷新"></a>二 之前写过一个简单listview的使用,在此基础做下拉刷新</h4><p><a target="_blank" rel="noopener" href="http://wxyass.com/2017/07/06/UIL--%E4%BD%BF%E7%94%A8uil%E4%B8%BAListView%E5%8A%A0%E8%BD%BD%E5%9B%BE%E7%89%87/">使用uil为ListView加载图片</a><br>将代码移植到本工程   </p>
<h5 id="2-1-将ListView控件用PtrClassicFrameLayout包起来"><a href="#2-1-将ListView控件用PtrClassicFrameLayout包起来" class="headerlink" title="2.1  将ListView控件用PtrClassicFrameLayout包起来"></a>2.1  将ListView控件用PtrClassicFrameLayout包起来</h5><pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
                xmlns:tools=&quot;http://schemas.android.com/tools&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;
    &gt;

    &lt;in.srain.cube.views.ptr.PtrClassicFrameLayout
        android:id=&quot;@+id/ptr&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        &gt;

        &lt;ListView
            android:id=&quot;@+id/listview&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            android:layout_marginBottom=&quot;10dp&quot;
            android:descendantFocusability=&quot;beforeDescendants&quot;
            android:dividerHeight=&quot;1dp&quot;
            android:footerDividersEnabled=&quot;false&quot;/&gt;
    &lt;/in.srain.cube.views.ptr.PtrClassicFrameLayout&gt;

&lt;/RelativeLayout&gt;
</code></pre>
<h5 id="2-2-修改MainActivity中的代码"><a href="#2-2-修改MainActivity中的代码" class="headerlink" title="2.2 修改MainActivity中的代码"></a>2.2 修改MainActivity中的代码</h5><pre><code class="java">ptr = (PtrClassicFrameLayout) findViewById(R.id.ptr);
//2设置刷新回调
ptr.setPtrHandler(new PtrDefaultHandler() &#123;

    // 在这个方法回调中加载新数据,并关闭动画
    @Override
    public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) &#123;
        // 获取新数据
        count  = end;
        end = count+num;
        getData();
        adapter.notifyDataSetChanged();
        // 关闭下拉刷新的动画
        ptr.refreshComplete();
    &#125;

    //1 将listview传入
    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) &#123;
        return super.checkCanDoRefresh(frame, listview, header);
    &#125;
&#125;);  
</code></pre>
<p>通过findViewById先找到PtrClassicFrameLayout控件,然后设置刷新回调,<br>在checkCanDoRefresh方法中将listview传进去,<br>在onRefreshBegin方法中获取新的数据并关闭下拉刷新的动画.      </p>
<p>在onRefreshBegin方法中要根据产品的需求去获取数据, 需要跟产品和后台商量好到底刷新什么数据.    </p>
<p>注意:下拉刷新的动画是ptr框架自带的,若觉得不好看,可自己去他的原码修改,或者通过其提供的api自定义头部修改.      </p>
<h5 id="2-3-以上就是最简单的下拉刷新使用"><a href="#2-3-以上就是最简单的下拉刷新使用" class="headerlink" title="2.3 以上就是最简单的下拉刷新使用"></a>2.3 以上就是最简单的下拉刷新使用</h5><h4 id="三-自定义下拉刷新时的头部动画"><a href="#三-自定义下拉刷新时的头部动画" class="headerlink" title="三 自定义下拉刷新时的头部动画"></a>三 自定义下拉刷新时的头部动画</h4><h5 id="3-1-自定义头部动画-工程目录如图"><a href="#3-1-自定义头部动画-工程目录如图" class="headerlink" title="3.1 自定义头部动画,工程目录如图:"></a>3.1 自定义头部动画,工程目录如图:</h5><p><img src="http://images.wxyass.com/wxyass/images/20170708181820.png"></p>
<h5 id="3-2-附上CircleView的代码"><a href="#3-2-附上CircleView的代码" class="headerlink" title="3.2 附上CircleView的代码"></a>3.2 附上CircleView的代码</h5><pre><code class="java">import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

/**
 * CircleView 圆盘控件，可以旋转
 * Created by wxyass.
 */
public class CircleView extends View &#123;

    /**
     * 控件的半径
     */
    private int mRadius;

    /**
     * 绘制弧形的画笔
     */
    private Paint mArcPaint;

    /**
     * 绘制弧形的区域
     */
    private RectF mRange;


    private int[] colors = &#123;Color.RED, Color.BLUE, Color.YELLOW, Color.GREEN&#125;;

    public CircleView(Context context) &#123;
        this(context, null, 0);
    &#125;

    public CircleView(Context context, AttributeSet attrs) &#123;
        this(context, attrs, 0);
    &#125;

    public CircleView(Context context, AttributeSet attrs, int defStyleAttr) &#123;
        super(context, attrs, defStyleAttr);

        init();
    &#125;

    private void init() &#123;
        mArcPaint = new Paint();
        mArcPaint.setAntiAlias(true);
        mArcPaint.setDither(true);
        mArcPaint.setStyle(Paint.Style.FILL);
    &#125;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) &#123;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int width = 0;
        int height = 0;

        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);

        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);


        if (widthMode == MeasureSpec.EXACTLY) &#123;
            width = widthSize;
        &#125; else &#123;
            width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, getResources().getDisplayMetrics());
        &#125;

        if (heightMode == MeasureSpec.EXACTLY) &#123;
            height = heightSize;
        &#125; else &#123;
            height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, getResources().getDisplayMetrics());
        &#125;

        //获取半径
        mRadius = Math.min(width, height) / 2;
        /**
         * 设置宽高为固定值
         */
        setMeasuredDimension(mRadius * 2, mRadius * 2);

         mRange = new RectF(0, 0, mRadius * 2, mRadius * 2);
    &#125;


    @Override
    protected void onDraw(Canvas canvas) &#123;

        float degree = 360/colors.length/2f;

        for (int i = 0; i &lt; 8; i++) &#123;
            mArcPaint.setColor(colors[i%4]);
            canvas.drawArc(mRange,-90f+degree*i,degree,true,mArcPaint);
        &#125;

    &#125;
&#125;
</code></pre>
<h5 id="3-3-附上CustomUltraRefreshHeader的代码"><a href="#3-3-附上CustomUltraRefreshHeader的代码" class="headerlink" title="3.3 附上CustomUltraRefreshHeader的代码"></a>3.3 附上CustomUltraRefreshHeader的代码</h5><pre><code>import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import in.srain.cube.views.ptr.indicator.PtrIndicator;

/**
 *
 * 自定义刷新的头部
 * Created by wxyass.
 */
public class CustomUltraRefreshHeader extends RelativeLayout implements PtrUIHandler &#123;

    CircleView mCircleView;

    TextView mDescText;

    private ObjectAnimator anim;

    public CustomUltraRefreshHeader(Context context) &#123;
        this(context,null);
    &#125;

    public CustomUltraRefreshHeader(Context context, AttributeSet attrs) &#123;
        this(context, attrs,0);
    &#125;

    public CustomUltraRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr) &#123;
        super(context, attrs, defStyleAttr);

        initView();
    &#125;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) &#123;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec,100);
    &#125;

    /**
     * 初始化布局
     */
    private void initView() &#123;

        int circlewidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());

        mCircleView = new CircleView(getContext());

        LinearLayout.LayoutParams circleParams = new LinearLayout.LayoutParams(circlewidth,circlewidth);

        mCircleView.setLayoutParams(circleParams);

        mDescText = new TextView(getContext());

        LinearLayout.LayoutParams descParams = new LinearLayout.LayoutParams(circlewidth*3, ViewGroup.LayoutParams.WRAP_CONTENT);

        descParams.gravity = Gravity.CENTER;
        descParams.setMargins(circlewidth/2,0,0,0);
        mDescText.setLayoutParams(descParams);
        mDescText.setTextSize(12);
        mDescText.setTextColor(Color.GRAY);
        mDescText.setText(&quot;下拉刷新&quot;);

        //添加线性的父布局
        LinearLayout ll = new LinearLayout(getContext());
        LayoutParams llParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        llParams.addRule(CENTER_IN_PARENT);
        ll.setLayoutParams(llParams);
        ll.setPadding(10,10,10,10);

        ll.addView(mCircleView);
        ll.addView(mDescText);

        addView(ll);
    &#125;

    @Override
    public void onUIReset(PtrFrameLayout frame) &#123;
        //重置时，将动画置为初始状态
        mCircleView.setRotation(0f);
        Log.i(&quot;info&quot;,&quot;onUIReset&quot;);
    &#125;

    @Override
    public void onUIRefreshPrepare(PtrFrameLayout frame) &#123;
        mDescText.setText(&quot;下拉加载数据&quot;);
        Log.i(&quot;info&quot;,&quot;onUIRefreshPrepare&quot;);
    &#125;

    @Override
    public void onUIRefreshBegin(PtrFrameLayout frame) &#123;

        //开始刷新，启动动画
        anim = ObjectAnimator.ofFloat(mCircleView, &quot;rotation&quot;, mCircleView.getRotation(), mCircleView.getRotation()+360f)
                .setDuration(500);
        anim.setRepeatCount(ValueAnimator.INFINITE);
        anim.setRepeatMode(ValueAnimator.RESTART);
        anim.start();

        mDescText.setText(&quot;正在加载数据&quot;);
        Log.i(&quot;info&quot;,&quot;onUIRefreshBegin&quot;);
    &#125;

    @Override
    public void onUIRefreshComplete(PtrFrameLayout frame) &#123;
        anim.cancel();
        mDescText.setText(&quot;加载完成&quot;);
        Log.i(&quot;info&quot;,&quot;onUIRefreshComplete&quot;);
    &#125;

    @Override
    public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) &#123;
        int headerHeight = ptrIndicator.getHeaderHeight();//头部的高度
        int lastPosY = ptrIndicator.getLastPosY();//上一次滑动的Y偏移值
        int offsetToRefresh = ptrIndicator.getOffsetToRefresh();//舒心需要滑动的偏移量
        float offsetY = ptrIndicator.getOffsetY();//当前与上一次滑动处理的偏移值
        int currentPosY = ptrIndicator.getCurrentPosY();//当前系统偏移值

        if (isUnderTouch&amp;&amp;status== PtrFrameLayout.PTR_STATUS_PREPARE) &#123;

            mCircleView.setRotation(currentPosY);
            if(currentPosY&lt;offsetToRefresh&amp;&amp;lastPosY &gt;= offsetToRefresh)&#123;
                //表示不刷新了
                mDescText.setText(&quot;下拉加载数据&quot;);
            &#125;else if(currentPosY&gt;offsetToRefresh&amp;&amp;lastPosY&lt;=offsetToRefresh)&#123;
                mDescText.setText(&quot;松开加载更多&quot;);
            &#125;
        &#125;

       /* if (currentPos &lt; mOffsetToRefresh &amp;&amp; lastPos &gt;= mOffsetToRefresh) &#123;
            if (isUnderTouch &amp;&amp; status == PtrFrameLayout.PTR_STATUS_PREPARE) &#123;*//*
        Log.i(&quot;info&quot;,&quot;isUnderTouch&quot;+isUnderTouch+&quot;headHeight: &quot;+headerHeight+&quot; lastPosY &quot;+lastPosY+&quot; offsetToRefresh &quot;+offsetToRefresh+&quot; offsetY &quot;+offsetY+&quot; currentPosY &quot;+currentPosY);*/
    &#125;
&#125;    
</code></pre>
<h5 id="3-4-修改代码-调用自定义头部"><a href="#3-4-修改代码-调用自定义头部" class="headerlink" title="3.4 修改代码,调用自定义头部"></a>3.4 修改代码,调用自定义头部</h5><pre><code>//  自定义头部 下拉刷新时动画UI , 若不想用把下面3行代码注释掉
//创建我们的自定义头部视图
CustomUltraRefreshHeader header = new CustomUltraRefreshHeader(this);
//设置头部视图
ptr.setHeaderView(header);
//设置视图修改的回调，因为我们的CustomUltraRefreshHeader实现了PtrUIHandler
ptr.addPtrUIHandler(header);  
</code></pre>
<p>代码修改如图:<br><img src="http://images.wxyass.com/wxyass/images/20170708182459.png"></p>
<h5 id="3-5-修改清单文件的name属性-然后重跑项目-查看效果"><a href="#3-5-修改清单文件的name属性-然后重跑项目-查看效果" class="headerlink" title="3.5 修改清单文件的name属性,然后重跑项目,查看效果"></a>3.5 修改清单文件的name属性,然后重跑项目,查看效果</h5><pre><code>&lt;application
    android:name=&quot;.MyApplication&quot;
    android:allowBackup=&quot;true&quot;
    android:icon=&quot;@mipmap/ic_launcher&quot;
    android:label=&quot;@string/app_name&quot;
    android:supportsRtl=&quot;true&quot;
    android:theme=&quot;@style/AppTheme&quot;&gt;
    &lt;activity android:name=&quot;.UseHeadActivity&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;

            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;activity
        android:name=&quot;.ImageActivity&quot;
        android:screenOrientation=&quot;portrait&quot;/&gt;
&lt;/application&gt;
</code></pre>
<h5 id="3-6-新下拉刷新头部效果如下"><a href="#3-6-新下拉刷新头部效果如下" class="headerlink" title="3.6 新下拉刷新头部效果如下"></a>3.6 新下拉刷新头部效果如下</h5><p><img src="http://images.wxyass.com/wxyass/images/20170708185730.png">    </p>
<h4 id="四-在框架基础上-自定义listview实现上拉加载更多"><a href="#四-在框架基础上-自定义listview实现上拉加载更多" class="headerlink" title="四 在框架基础上,自定义listview实现上拉加载更多"></a>四 在框架基础上,自定义listview实现上拉加载更多</h4><h5 id="4-1-工程目录如图"><a href="#4-1-工程目录如图" class="headerlink" title="4.1 工程目录如图"></a>4.1 工程目录如图</h5><p><img src="http://images.wxyass.com/wxyass/images/20170708184403.png">   </p>
<h5 id="4-2-附上UltraRefreshListener代码"><a href="#4-2-附上UltraRefreshListener代码" class="headerlink" title="4.2 附上UltraRefreshListener代码"></a>4.2 附上UltraRefreshListener代码</h5><pre><code>/**
 * 数据接口的回调
 * Created by wxyass.
 */
public interface UltraRefreshListener &#123;

    //下拉刷新
    void onRefresh();

    //上拉加载
    void addMore();
&#125;
</code></pre>
<h5 id="4-3-附上UltraRefreshListView代码"><a href="#4-3-附上UltraRefreshListView代码" class="headerlink" title="4.3 附上UltraRefreshListView代码"></a>4.3 附上UltraRefreshListView代码</h5><pre><code>import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewParent;
import android.widget.AbsListView;
import android.widget.ListView;

import com.wxyass.tpultraptr.R;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

/**
 * Created by wxyass.
 */
public class UltraRefreshListView extends ListView implements PtrHandler, AbsListView.OnScrollListener &#123;

    private UltraRefreshListener mUltraRefreshListener;

    /**
     * 底部的布局:正在为您加载更多
     */
    private View footView;


    /**
     * 是否正在加载数据
     */
    private boolean isLoadData = false;

    /**
     * 是否是下拉刷新，主要在处理结果时使用
     */
    private boolean isRefresh = false;

    public UltraRefreshListView(Context context) &#123;
        this(context, null);
    &#125;

    public UltraRefreshListView(Context context, AttributeSet attrs) &#123;
        this(context, attrs, 0);
    &#125;

    public UltraRefreshListView(Context context, AttributeSet attrs, int defStyleAttr) &#123;
        super(context, attrs, defStyleAttr);
        //初始化布局，及添加一个跟布局
        initView();
    &#125;

    private void initView() &#123;
        footView = LayoutInflater.from(getContext()).inflate(R.layout.foot_ultra_refresh_listview, null);

        setOnScrollListener(this);
    &#125;

    // 开始刷新动画
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) &#123;

        isLoadData = true;
        isRefresh = true;
        //下拉刷新的回调
        if (mUltraRefreshListener != null) &#123;

            mUltraRefreshListener.onRefresh();
        &#125;
    &#125;

    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) &#123;
        //  PtrHandler 的接口回调，是否能够加载数据的判断
        return !isLoadData &amp;&amp; checkContentCanBePulledDown(frame, content, header);
    &#125;

    // 从PtrHandler的默认实现类 PtrDefaultHandler中找到的，用以判断是否可以下拉刷新
    public static boolean checkContentCanBePulledDown(PtrFrameLayout frame, View content, View header) &#123;
        return !canChildScrollUp(content);

    &#125;

    // 从PtrHandler的默认实现类 PtrDefaultHandler中找到的，用以判断是否可以下拉刷新
    public static boolean canChildScrollUp(View view) &#123;
        if (android.os.Build.VERSION.SDK_INT &lt; 14) &#123;
            if (view instanceof AbsListView) &#123;
                final AbsListView absListView = (AbsListView) view;
                return absListView.getChildCount() &gt; 0
                        &amp;&amp; (absListView.getFirstVisiblePosition() &gt; 0 || absListView.getChildAt(0)
                        .getTop() &lt; absListView.getPaddingTop());
            &#125; else &#123;
                return view.getScrollY() &gt; 0;
            &#125;
        &#125; else &#123;
            return view.canScrollVertically(-1);
        &#125;
    &#125;

    /**
     * 设置ListView的监听回调
     */
    public void setUltraRefreshListener(UltraRefreshListener mUltraRefreshListener) &#123;
        this.mUltraRefreshListener = mUltraRefreshListener;
    &#125;

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) &#123;

    &#125;

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) &#123;
        /*Log.i(&quot;info&quot;,&quot;isLoadData:&quot;+isLoadData+&quot; totalItemCount &quot;+totalItemCount+&quot; firstVisibleItem &quot;+
                firstVisibleItem+&quot; visibleItemCount &quot;+ visibleItemCount);
*/
        //加载更多的判断
        if (totalItemCount &gt; 1 &amp;&amp; !isLoadData &amp;&amp; totalItemCount == firstVisibleItem + visibleItemCount) &#123;
            isRefresh = false;
            isLoadData = true;
            addFooterView(footView);
            mUltraRefreshListener.addMore();
        &#125;
    &#125;

    //刷新完成的后调用此方法还原布局
    public void refreshComplete() &#123;
        isLoadData = false;
        if (isRefresh) &#123;
            //获取其父控件，刷新
            ViewParent parent = getParent();
            if (parent instanceof PtrClassicFrameLayout) &#123;
                ((PtrClassicFrameLayout) parent).refreshComplete();
            &#125;
        &#125; else &#123;
            removeFooterView(footView);
        &#125;
    &#125;
&#125;
</code></pre>
<h5 id="4-4-附上底部加载更多布局-foot-ultra-refresh-listview-xml"><a href="#4-4-附上底部加载更多布局-foot-ultra-refresh-listview-xml" class="headerlink" title="4.4 附上底部加载更多布局 foot_ultra_refresh_listview.xml"></a>4.4 附上底部加载更多布局 foot_ultra_refresh_listview.xml</h5><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:orientation=&quot;vertical&quot;&gt;


    &lt;TextView
        android:id=&quot;@+id/tv_load&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:layout_gravity=&quot;center&quot;
        android:layout_marginBottom=&quot;10dp&quot;
        android:layout_marginTop=&quot;10dp&quot;
        android:text=&quot;正在为您加载更多&quot;/&gt;

    &lt;Button
        android:id=&quot;@+id/btn_load_fail&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:layout_gravity=&quot;center&quot;
        android:layout_marginBottom=&quot;10dp&quot;
        android:layout_marginTop=&quot;10dp&quot;
        android:text=&quot;重新加载&quot;
        android:visibility=&quot;gone&quot;/&gt;

&lt;/LinearLayout&gt;
</code></pre>
<h5 id="4-5-修改界面布局-用PtrClassicFrameLayout包裹自定义ListView"><a href="#4-5-修改界面布局-用PtrClassicFrameLayout包裹自定义ListView" class="headerlink" title="4.5 修改界面布局,用PtrClassicFrameLayout包裹自定义ListView"></a>4.5 修改界面布局,用PtrClassicFrameLayout包裹自定义ListView</h5><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              android:orientation=&quot;vertical&quot;&gt;

    &lt;in.srain.cube.views.ptr.PtrClassicFrameLayout
        android:id=&quot;@+id/ultra_ptr&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;&gt;

        &lt;com.wxyass.tpultraptr.RefreshList.view.UltraRefreshListView
            android:id=&quot;@+id/ultra_lv&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;/&gt;

    &lt;/in.srain.cube.views.ptr.PtrClassicFrameLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>
<h5 id="4-6-修改代码-完成下列刷新-上拉加载的回调"><a href="#4-6-修改代码-完成下列刷新-上拉加载的回调" class="headerlink" title="4.6 修改代码,完成下列刷新,上拉加载的回调"></a>4.6 修改代码,完成下列刷新,上拉加载的回调</h5><p>修改上拉加载如图:<br><img src="http://images.wxyass.com/wxyass/images/20170708191158.png">   </p>
<p>附上UseRefreshListActivity代码  </p>
<pre><code>import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;

import com.wxyass.tpultraptr.RefreshList.refreshhead.CustomUltraRefreshHeader;
import com.wxyass.tpultraptr.RefreshList.view.UltraRefreshListView;
import com.wxyass.tpultraptr.RefreshList.view.UltraRefreshListener;

import java.util.ArrayList;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;

/**
 * Created by wxyass.
 */
public class UseRefreshListActivity extends AppCompatActivity  &#123;

    private PtrClassicFrameLayout mPtrFrame;

    private UltraRefreshListView mLv;

    ImgListAdapter adapter;
    ArrayList&lt;String&gt; imageUrl;

    int count = 1; // 起始位置
    int num = 5; // 每次下拉刷新加载几张图片,可自己修改
    int end = count+ num;// 刷新后的结束位置

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_listview_ultra);

        imageUrl = new ArrayList&lt;String&gt;();
        // 初始化数据
        getData(0);

        //查找控件
        mPtrFrame = ((PtrClassicFrameLayout) findViewById(R.id.ultra_ptr));

        mLv = ((UltraRefreshListView) findViewById(R.id.ultra_lv));

        //  自定义头部 下拉刷新时动画UI , 若不想用把下面3行代码注释掉

        //创建我们的自定义头部视图
        CustomUltraRefreshHeader header = new CustomUltraRefreshHeader(this);
        //设置头部视图
        mPtrFrame.setHeaderView(header);
        //设置视图修改的回调，因为我们的CustomUltraRefreshHeader实现了PtrUIHandler
        mPtrFrame.addPtrUIHandler(header);


        //设置数据刷新的会回调，这里需要传入一个PtrHandler, 因为UltraRefreshListView实现了PtrHandler
        mPtrFrame.setPtrHandler(mLv);

        adapter = new ImgListAdapter(imageUrl, getApplicationContext());
        mLv.setAdapter(adapter);



        /* PauseOnScrollListener这个类来控制ListView,GridView滑动过程中停止去加载图片.
        第一个参数就是我们的图片加载对象ImageLoader,
        第二个是控制是否在滑动过程中暂停加载图片，如果需要暂停传true就行了，
        第三个参数控制猛的滑动界面的时候图片是否加载。*/
        // 在自定义控件OnScrollListener已经对setOnScrollListener做了监听,用于加载更多,这里重写的话,加载更多就不能用了
        //mLv.setOnScrollListener(new PauseOnScrollListener(ImageLoader.getInstance(), false, true));

        // listview条目的点击事件
        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() &#123;
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) &#123;
                Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                intent.putExtra(&quot;url&quot;, imageUrl.get(position));
                startActivity(intent);
            &#125;
        &#125;);

        //设置上拉下拉的数据刷新回调接口
        mLv.setUltraRefreshListener(new UltraRefreshListener() &#123;
            // 上拉加载
            @Override
            public void addMore() &#123;
                mPtrFrame.postDelayed(new Runnable() &#123;
                    @Override
                    public void run() &#123;

                        // 获取新数据
                        count  = end;
                        end = count+num;
                        getData(1);
                        adapter.notifyDataSetChanged();
                        // 关闭下拉刷新的动画
                        stopResh();
                    &#125;
                &#125;,1000);
            &#125;
            // 下拉刷新
            @Override
            public void onRefresh() &#123;
                mPtrFrame.postDelayed(new Runnable() &#123;
                    @Override
                    public void run() &#123;
                        // 获取新数据
                        count  = end;
                        end = count+num;
                        getData(0);
                        adapter.notifyDataSetChanged();
                        // 关闭下拉刷新的动画
                        stopResh();
                    &#125;
                &#125;,1000);
            &#125;


        &#125;);
    &#125;

    String picName = &quot;Pic_000000&quot;;
    // 获取新数据
    private void getData(int isRefresh) &#123; // 0下拉刷新, 1上拉加载
        String imageString;
        for (int i = count; i &lt; end; i++)
        &#123;
            int length = String.valueOf(i).length();
            imageString = picName.substring(0,picName.length()-length)+i;
            imageString = &quot;http://oss.wxyass.com/private/images/001/&quot;+imageString+&quot;.jpg&quot;;
            if(0==isRefresh)&#123;
                imageUrl.add(0,imageString);// http://oss.wxyass.com/private/images/001/Pic_000076.jpg
            &#125;else&#123;
                imageUrl.add(imageString);
            &#125;
        &#125;
    &#125;
    // 关闭动画(下拉刷新的动画)
    public void stopResh()&#123;
        mLv.refreshComplete();
    &#125;
&#125; 
</code></pre>
<h5 id="4-6-修改清单文件的Activity入口-重跑项目-查看效果"><a href="#4-6-修改清单文件的Activity入口-重跑项目-查看效果" class="headerlink" title="4.6 修改清单文件的Activity入口,重跑项目,查看效果."></a>4.6 修改清单文件的Activity入口,重跑项目,查看效果.</h5><p><img src="http://images.wxyass.com/wxyass/images/20170708191631.png">  </p>
<h5 id="4-7-效果如下-当加载完成-底部自动隐藏"><a href="#4-7-效果如下-当加载完成-底部自动隐藏" class="headerlink" title="4.7 效果如下,当加载完成,底部自动隐藏"></a>4.7 效果如下,当加载完成,底部自动隐藏</h5><p><img src="http://images.wxyass.com/wxyass/images/20170708191904.png">  </p>
<h4 id="五-以上-android-Ultra-Pull-To-Refresh的使用介绍基本这样了"><a href="#五-以上-android-Ultra-Pull-To-Refresh的使用介绍基本这样了" class="headerlink" title="五 以上,android-Ultra-Pull-To-Refresh的使用介绍基本这样了"></a>五 以上,android-Ultra-Pull-To-Refresh的使用介绍基本这样了</h4><p><a target="_blank" rel="noopener" href="http://oss.wxyass.com/wxyass/demo/TPultraptr2.rar">本文项目源码</a>    </p>
<p>参考: 网上一些博客讲解<br><a target="_blank" rel="noopener" href="http://blog.csdn.net/yanzhenjie1003/article/details/53450488">http://blog.csdn.net/yanzhenjie1003/article/details/53450488</a><br><a target="_blank" rel="noopener" href="http://blog.csdn.net/lisdye2/article/details/51449716">http://blog.csdn.net/lisdye2/article/details/51449716</a><br><a target="_blank" rel="noopener" href="http://blog.csdn.net/sbvfhp/article/details/44959917">http://blog.csdn.net/sbvfhp/article/details/44959917</a><br><a target="_blank" rel="noopener" href="http://blog.csdn.net/mcy478643968/article/details/47401013">http://blog.csdn.net/mcy478643968/article/details/47401013</a><br><a target="_blank" rel="noopener" href="http://www.cnblogs.com/itgungnir/p/6211021.html">http://www.cnblogs.com/itgungnir/p/6211021.html</a><br><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/543b4c110b88">http://www.jianshu.com/p/543b4c110b88</a>    </p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2017/07/06/ListView/ListView--ListView%E4%B8%8A%E6%8B%89%E5%8A%A0%E8%BD%BD%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0/" data-id="ckvc340py002o5dfyhd7b02wx" data-title="ListView上拉加载下拉刷新" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/07/11/RecyclerView/RecyclerView--5.x%E4%B9%8BRecyclerView%E7%9A%84%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          5.x之RecyclerView的简单使用
        
      </div>
    </a>
  
  
    <a href="/2017/07/06/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86--%E4%BD%BF%E7%94%A8uil%E4%B8%BAListView%E5%8A%A0%E8%BD%BD%E5%9B%BE%E7%89%87/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">使用uil为ListView加载图片</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activity/">Activity</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android-Studio%E4%BB%8B%E7%BB%8D/">Android Studio介绍</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E6%A8%A1%E6%9D%BF/">Android模板</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/BaseRecyclerViewAdapterHelper/">BaseRecyclerViewAdapterHelper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Bug%E9%97%AE%E9%A2%98/">Bug问题</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Button/">Button</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/EditText/">EditText</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Fragment/">Fragment</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Gradle/">Gradle</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ListView/">ListView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MD%E8%AF%AD%E6%B3%95/">MD语法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MyEclipse/">MyEclipse</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/OSS/">OSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RecyclerView/">RecyclerView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SQL%E5%9F%BA%E7%A1%80/">SQL基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/UI%E6%8E%A7%E4%BB%B6/">UI控件</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View/">View</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ViewPager/">ViewPager</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View%E7%AF%87/">View篇</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/as%E6%8A%A5%E9%94%99/">as报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jar%E5%8C%85/">jar包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/targetSdkVersion/">targetSdkVersion</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%83%E7%89%9B%E4%BA%91/">七牛云</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%8C%E7%BB%B4%E7%A0%81/">二维码</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%A0%E9%99%A4%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98/">删除图片缓存</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/">升级报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">博客搭建</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8E%BB%E6%8E%89v7%E5%8C%85/">去掉v7包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/">图片处理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%A4%9A%E5%AA%92%E4%BD%93/">多媒体</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%9A%E5%88%B6%E7%B1%BB/">定制类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA/">小米手机</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/">广播机制</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/">微博分享</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%89%93%E5%8C%85APK%E6%8A%A5%E9%94%99/">打包APK报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/">持久化存储</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9DatePicker/">时间选择DatePicker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1/">服务</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9D%83%E9%99%90/">权限</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/">构建基类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9B%91%E5%90%AC%E9%94%81%E5%B1%8F/">监听锁屏</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%B3%BB%E7%BB%9F%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/">系统页面跳转</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/">艺术探索</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%BB%E5%8F%96txt/">读取txt</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BE%93%E5%85%A5%E6%B3%95/">输入法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8/">音乐播放器</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%BB%91%E9%A9%AC%E5%8D%AB%E5%A3%AB/">黑马卫士</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Activity/" rel="tag">Activity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio/" rel="tag">Android Studio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" rel="tag">Android Studio介绍</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E6%A8%A1%E6%9D%BF/" rel="tag">Android模板</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/BaseRecyclerViewAdapterHelper/" rel="tag">BaseRecyclerViewAdapterHelper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Bug%E9%97%AE%E9%A2%98/" rel="tag">Bug问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Button/" rel="tag">Button</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/EditText/" rel="tag">EditText</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Fragment/" rel="tag">Fragment</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gradle/" rel="tag">Gradle</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MD%E8%AF%AD%E6%B3%95/" rel="tag">MD语法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyEclipse/" rel="tag">MyEclipse</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OSS/" rel="tag">OSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RecyclerView/" rel="tag">RecyclerView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SQL%E5%9F%BA%E7%A1%80/" rel="tag">SQL基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/UI%E6%8E%A7%E4%BB%B6/" rel="tag">UI控件</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View/" rel="tag">View</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ViewPager/" rel="tag">ViewPager</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View%E7%AF%87/" rel="tag">View篇</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/as%E6%8A%A5%E9%94%99/" rel="tag">as报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jar%E5%8C%85/" rel="tag">jar包</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/targetSdkVersion/" rel="tag">targetSdkVersion</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" rel="tag">七牛云</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" rel="tag">升级报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" rel="tag">图片处理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" rel="tag">多媒体</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" rel="tag">工作问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" rel="tag">广播机制</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" rel="tag">应用详情</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" rel="tag">微博分享</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" rel="tag">持久化存储</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1/" rel="tag">服务</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%83%E9%99%90/" rel="tag">权限</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" rel="tag">构建基类</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E6%89%8B/" rel="tag">练手</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" rel="tag">艺术探索</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" rel="tag">输入法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" rel="tag">高级技巧</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Activity/" style="font-size: 12.5px;">Activity</a> <a href="/tags/Android-Studio/" style="font-size: 10px;">Android Studio</a> <a href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" style="font-size: 12.5px;">Android Studio介绍</a> <a href="/tags/Android%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">Android基础</a> <a href="/tags/Android%E6%A8%A1%E6%9D%BF/" style="font-size: 10px;">Android模板</a> <a href="/tags/BaseRecyclerViewAdapterHelper/" style="font-size: 10px;">BaseRecyclerViewAdapterHelper</a> <a href="/tags/Bug%E9%97%AE%E9%A2%98/" style="font-size: 10px;">Bug问题</a> <a href="/tags/Button/" style="font-size: 10px;">Button</a> <a href="/tags/EditText/" style="font-size: 10px;">EditText</a> <a href="/tags/Fragment/" style="font-size: 18.75px;">Fragment</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/ListView/" style="font-size: 17.5px;">ListView</a> <a href="/tags/MD%E8%AF%AD%E6%B3%95/" style="font-size: 11.25px;">MD语法</a> <a href="/tags/MyEclipse/" style="font-size: 13.75px;">MyEclipse</a> <a href="/tags/OSS/" style="font-size: 11.25px;">OSS</a> <a href="/tags/RecyclerView/" style="font-size: 12.5px;">RecyclerView</a> <a href="/tags/SQL%E5%9F%BA%E7%A1%80/" style="font-size: 10px;">SQL基础</a> <a href="/tags/UI%E6%8E%A7%E4%BB%B6/" style="font-size: 15px;">UI控件</a> <a href="/tags/View/" style="font-size: 10px;">View</a> <a href="/tags/ViewPager/" style="font-size: 10px;">ViewPager</a> <a href="/tags/View%E7%AF%87/" style="font-size: 10px;">View篇</a> <a href="/tags/as%E6%8A%A5%E9%94%99/" style="font-size: 10px;">as报错</a> <a href="/tags/jar%E5%8C%85/" style="font-size: 10px;">jar包</a> <a href="/tags/targetSdkVersion/" style="font-size: 10px;">targetSdkVersion</a> <a href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" style="font-size: 10px;">七牛云</a> <a href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" style="font-size: 10px;">升级报错</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 12.5px;">博客搭建</a> <a href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" style="font-size: 15px;">图片处理</a> <a href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" style="font-size: 12.5px;">多媒体</a> <a href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" style="font-size: 16.25px;">工作问题</a> <a href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" style="font-size: 12.5px;">广播机制</a> <a href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" style="font-size: 10px;">应用详情</a> <a href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" style="font-size: 10px;">微博分享</a> <a href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" style="font-size: 13.75px;">持久化存储</a> <a href="/tags/%E6%9C%8D%E5%8A%A1/" style="font-size: 12.5px;">服务</a> <a href="/tags/%E6%9D%83%E9%99%90/" style="font-size: 10px;">权限</a> <a href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" style="font-size: 10px;">构建基类</a> <a href="/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 11.25px;">生活</a> <a href="/tags/%E7%BB%83%E6%89%8B/" style="font-size: 11.25px;">练手</a> <a href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" style="font-size: 10px;">艺术探索</a> <a href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" style="font-size: 10px;">输入法</a> <a href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" style="font-size: 11.25px;">高级技巧</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">October 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">July 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">June 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">April 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">September 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/05/">May 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/11/03/Android%20Studio/Github%E4%B8%8A%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81/">Github上提交代码</a>
          </li>
        
          <li>
            <a href="/2017/10/31/RecyclerView/BaseRecyclerViewAdapterHelper%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/">BaseRecyclerViewAdapterHelper库的基本使用方法</a>
          </li>
        
          <li>
            <a href="/2017/10/31/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E4%B8%83%E7%89%9B%E4%BA%91--%E4%B8%83%E7%89%9B%E4%BA%91%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87/">七牛云快速上传图片</a>
          </li>
        
          <li>
            <a href="/2017/10/31/Gradle/Gradle--Gradle%E6%B7%BB%E5%8A%A0%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%8A%A5%E5%BC%82%E5%B8%B8/">Gradle添加第三方库报异常</a>
          </li>
        
          <li>
            <a href="/2017/10/26/Android%20Studio/%E8%A7%A3%E5%86%B3Android-Studio-Gradle-%E9%94%99%E8%AF%AF-%E7%BC%96%E7%A0%81GBK%E7%9A%84%E4%B8%8D%E5%8F%AF%E6%98%A0%E5%B0%84%E5%AD%97%E7%AC%A6/">解决Android Studio Gradle 错误 编码GBK的不可映射字符</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 wxyass<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>